/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/itframe">itframe</a> All rights reserved.
 */
package com.rise.itframe.modules.inv.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.rise.itframe.common.persistence.Page;
import com.rise.itframe.common.web.BaseController;
import com.rise.itframe.modules.inv.entity.ReviewUser;
import com.rise.itframe.modules.inv.service.ReviewUserService;

/**
 * 发票登记信息Controller
 * @author ming
 * @version 2017-12-31
 */
@Controller
@RequestMapping(value = "${adminPath}/inv/reviewUser")
public class ReviewUserController extends BaseController {

    @Autowired
    private ReviewUserService reviewUserService;

    @ModelAttribute
    public ReviewUser get(@RequestParam(required = false) String id) {
        ReviewUser entity = null;
        if (org.apache.commons.lang3.StringUtils.isNotBlank(id)){
            entity = reviewUserService.get(id);
        }
        if (entity == null){
            entity = new ReviewUser();
        }
        return entity;
    }

    // @RequiresPermissions("inv:reviewUser:view")
    @RequestMapping(value = {"list", ""})
    @ResponseBody
    public Page<ReviewUser> list(ReviewUser reviewUser, HttpServletRequest request, HttpServletResponse response,
        Model model) {
        Page<ReviewUser> page = reviewUserService.findPage(new Page<ReviewUser>(request, response), reviewUser);
        model.addAttribute("page", page);
        return page;
    }

    // @RequiresPermissions("inv:reviewUser:view")
    @RequestMapping(value = "form")
    @ResponseBody
    public ReviewUser form(ReviewUser reviewUser, Model model) {
        model.addAttribute("reviewUser", reviewUser);
        return reviewUser;
    }

    // @RequiresPermissions("inv:reviewUser:edit")
    @RequestMapping(value = "save")
    @ResponseBody
    public String save(ReviewUser reviewUser, Model model, RedirectAttributes redirectAttributes) {
        reviewUserService.save(reviewUser);
        addMessage(redirectAttributes, "保存评审用户成功");
        return "success";
    }

    // @RequiresPermissions("inv:reviewUser:edit")
    @RequestMapping(value = "delete")
    @ResponseBody
    public String delete(ReviewUser reviewUser, RedirectAttributes redirectAttributes) {
        reviewUserService.delete(reviewUser);
        addMessage(redirectAttributes, "删除评审用户成功");
        return "success";
    }

}